<?php

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
#	FILE:			includes/custom/userprefs.php
#	FUNCTION:		Custom handler for the User Preferences page
#	AUTHOR:			Cameron Morrow
#	CREATED:		09/08/2005
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Get table property information for this data
$data_formatting = getRecord("SELECT * FROM " . $PROJECT_DB_TABLES["table_properties"] . " WHERE tp_field = 'u_fname' OR tp_field = 'u_lname' OR tp_field = 'u_email' OR tp_field = 'u_newsletter_groups' ORDER BY tp_formorder ASC");

# Create TableProperties
$data_properties = new TableProperties();

# Add properties
foreach ($data_formatting as $row_format) {

	$data_properties -> addProperty(new TableProperty($row_format["tp_field"], $row_format));
}

# Check for submission
if (@$_POST["submitted"]) {

	# Save
	$data_properties -> attemptToSave("edit", "u_id", false, $USER -> getID());

	# Update User
	$USER -> updateDataFromDatabase();
}


# Get Data
$edit_sql = "SELECT * FROM " . $PROJECT_DB_TABLES["users"] . " WHERE u_login_name = '" . $USER -> getLoginName() . "'";
$current_data = getRecord($edit_sql);

# Title
$PAGE_NAME = $USER -> getFirstName() . " " . $USER -> getLastName() . " User Preferences";

# Header
addContent("<h2><em>" .$USER -> getFirstName() . " " . $USER -> getLastName() . "</em> User Preferences</h2>");

# Prompt to change password
addContent("<form name=\"dummyform\" id=\"dummyform\" method=\"get\" action=\"#\">" .
	"<p>Click the button below to change your password:</p>" .
	"<p><input type=\"button\" value=\"Change Password\" onclick=\"openChangePasswordWin();\" /></p>" .
	"</form>");

# Draw form
addContent($data_properties -> generateInputForm("edit", $current_data[0], $USER -> getID(), "Change your preferences:", true));

?>